/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import simplemetrosystem.control.EditCommandManager;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.model.Element.MetroEdge;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.view.MetroFrame;
import simplemetrosystem.view.table.Exceptions.InformationPanelException;

/**
 *
 * @author Eric Qian
 */
public class RemoveEdgeActionListener implements ActionListener {

    /**
     * 
     * @param frame
     * @param edge 
     */
    public RemoveEdgeActionListener(MetroFrame frame, MetroEdge edge) {
        this.frame = frame;
        this.edge = edge;
    }

    /**
     * 
     * @param e
     */
    public void actionPerformed(ActionEvent e) {
        if (edge != null && frame.getInfPane().getElemTab() == InformationPane.EDGE) {
            System.out.println("Remove " + edge.getDisplayName());
            EditCommandManager.getInstance().removeEdge(edge);
            try {
                frame.getInfPane().setFocus(InformationPane.ALL_EDGE, null);
            } catch (InformationPanelException ex) {
                ex.printStackTrace();
            }
        } else {
            int selectRow = frame.getInfPane().getAllEdgeTable().getSelectedRow();
            if (selectRow > -1) {
                edge = ElementManager.getInstance().getEdgeAt(selectRow);
                System.out.println("Remove " + edge.getDisplayName());
                EditCommandManager.getInstance().
                        removeEdge(edge);
            } else {
                System.out.println("Remove Null");
            }
        }
    }
    private MetroFrame frame;
    private MetroEdge edge;
}
